package com.aaa.ps.controller;

import com.aaa.common.entity.Menu;
import com.aaa.common.util.Constants;
import com.aaa.common.util.Result;
import com.aaa.ps.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * fileName:MenuController
 * description:
 * author:zz
 * createTime:2020/8/25 16:32
 * version:1.0.0
 */
@RestController
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private MenuService menuService;


    /**
     * 获取树数据
     * @return
     */
    @GetMapping("menuTree")
    public Object menuTree(){
        return menuService.treeData();
    }
    /**
     * 根据用户ID获取树数据
     * @return
     */
    @GetMapping("menuTreeByUserId")
    public Object menuTreeByUserId(Integer userId){
        return new Result<>(Constants.RESULT.SUCCESS,Constants.RESULT.SUCMESSAGE,menuService.treeDataByUserId(userId));
    }
    /**
     * 根据ID删除
     * @param menuId
     * @return
     */
    @DeleteMapping("deleteByPrimaryKey")
    public int deleteByPrimaryKey(Integer menuId){
        //修改代码
        System.out.println(1111);
        //完善了扫描功能
        System.out.println(3333);
        //添加什么功能
        System.out.println(2222);
      return   menuService.deleteByPrimaryKey(menuId);
    }

    /**
     * 添加
     * @param record
     * @return
     */
    @PostMapping("insertSelective")
    public int insertSelective(@RequestBody Menu record){
        return  menuService.insertSelective(record);
    }

    /**
     * 根据ID查询
     * @param menuId
     * @return
     */
    @GetMapping("selectByPrimaryKey")
    public Menu selectByPrimaryKey(Integer menuId){
        return menuService.selectByPrimaryKey(menuId);
    }

    /**
     * 更新
     * @param record
     * @return
     */
    @PutMapping("updateByPrimaryKeySelective")
    public int updateByPrimaryKeySelective(@RequestBody  Menu record){
        return  menuService.updateByPrimaryKeySelective(record);
    }

    /**
     * 列表查询
     * @return
     */
    @GetMapping("selectAll")
    public List<Menu> selectAll(){
        return  menuService.selectAll();
    }
}
